﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ObligorCase", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(ObligorCase))]
    public class ObligorCaseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IObligorCase clazz;
        
        public ObligorCaseSerializer(IObligorCase clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ClaimData");
            if (clazz.ClaimData!=null) {
                global::Xtee.Core.SerializationMetadata metaClaimData = this.GetMetaData(clazz.ClaimData);
                Writer.WriteTypeAttribute(metaClaimData.TypeQualifiedName.Namespace, metaClaimData.TypeQualifiedName.Name);
                metaClaimData.NewSerializer(clazz.ClaimData).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ClaimData");
            }
            Writer.WriteEndElement();
            if (((clazz.ObligorData == null) 
                        || (clazz.ObligorData.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "ObligorData");
            }
            for (int x = 0; ((clazz.ObligorData != null) 
                        && (x < clazz.ObligorData.Count)); x = (x + 1)) {
                Writer.WriteStartElement("ObligorData");
                if (clazz.ObligorData[x]!=null) {
                    global::Xtee.Core.SerializationMetadata metaObligorData = this.GetMetaData(clazz.ObligorData[x]);
                    Writer.WriteTypeAttribute(metaObligorData.TypeQualifiedName.Namespace, metaObligorData.TypeQualifiedName.Name);
                    metaObligorData.NewSerializer(clazz.ObligorData[x]).WriteXml(Writer);
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ObligorData");
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ClaimData") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ObligorCase>ClaimData");
                }
                global::Xtee.Core.SerializationMetadata metaClaimData = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IClaimData>(Reader, "ClaimData", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.ClaimData = metaClaimData.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IClaimData>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ClaimData");
                    metaClaimData.NewSerializer(clazz.ClaimData).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ObligorCase>ClaimData", Reader.LocalName);
            }
            clazz.ObligorData = new System.Collections.Generic.List<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IObligorData>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "ObligorData")); ) {
                if (Reader.LocalName=="ObligorData") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ObligorCase>ObligorData");
                    }
                    global::Xtee.Core.SerializationMetadata metaObligorData = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IObligorData>(Reader, "ObligorData", "http://producers.kis.xtee.riik.ee/producer/kis");
                    global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IObligorData item = metaObligorData.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IObligorData>();
                    clazz.ObligorData.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("ObligorData");
                        metaObligorData.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ObligorCase>ObligorData", Reader.LocalName);
                }
            }
            if ((clazz.ObligorData.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "ObligorData");
            }
        }
    }
}
